Skip to content

Conversation

@iverase
Copy link
Contributor

@iverase iverase commented Mar 13, 2025

We are using the java command buckets.stream().map(...).toList() to build internal aggregation with sampling. While this is correct it has a side effect, the final list is normally oversize. In this case we know the length of the final list, therefore let's create list of the right size as we can have thousand of those objects on heap.

@elasticsearchmachine elasticsearchmachine added the Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) label Mar 13, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-analytical-engine (Team:Analytics)

Copy link
Contributor

@craigtaverner craigtaverner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Amusingly, the move from functional style, to classic java for loops, did not really increase the number of lines of code.

@craigtaverner
Copy link
Contributor

Perhaps we should add the auto-backport label?

@idegtiarenko
Copy link
Contributor

@iverase out of curiosity, what scenarios lead to a list with unnecessary big capacity?
It looks like we are always building from buckets that is list with a known size.

@iverase
Copy link
Contributor Author

iverase commented Mar 13, 2025

@idegtiarenko the method #toList initialise the arrays the standard way (new ArrayList()) so you end up with empty slots:

image

@iverase iverase added the auto-backport Automatically create backport pull requests when merged label Mar 13, 2025
@iverase iverase merged commit 6036a1e into elastic:main Mar 13, 2025
17 checks passed
@iverase iverase deleted the samplerAgg branch March 13, 2025 16:14
@elasticsearchmachine
Copy link
Collaborator

💚 Backport successful

Status Branch Result
8.x
9.0

iverase added a commit to iverase/elasticsearch that referenced this pull request Mar 13, 2025
Avoid oversize list in internal aggregations.
iverase added a commit to iverase/elasticsearch that referenced this pull request Mar 13, 2025
Avoid oversize list in internal aggregations.
elasticsearchmachine pushed a commit that referenced this pull request Mar 13, 2025
elasticsearchmachine pushed a commit that referenced this pull request Mar 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Analytics/Aggregations Aggregations auto-backport Automatically create backport pull requests when merged >non-issue Team:Analytics Meta label for analytical engine team (ESQL/Aggs/Geo) v8.19.0 v9.0.1 v9.1.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants